<!DOCTYPE html>
<html lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head th:include="/common/inc::header"/>
<body>
<form class="layui-form">
    <input name="id" id="id" type="hidden"/>
    <br/>
    <div class="layui-form-item" style="margin-left: 20%">
        <label class="layui-form-label">退款凭证号:</label>
        <div class="layui-input-inline">
            <input type="text" name="refundNo" id="refundNo" autocomplete="off" required
                   class="layui-input">
        </div>
    </div>
    <hr class="layui-bg-gray">
    <div class="layui-form-item" style="margin-left: 20%">
        <label class="layui-form-label">订单总额:</label>
        <div class="layui-input-inline">
            <input type="text" name="billFee" id="billFee" autocomplete="off" required readonly
                   class="layui-input">
        </div>
    </div>
    <hr class="layui-bg-gray">
    <div class="layui-form-item" style="margin-left: 20%">
        <label class="layui-form-label">退款金额:</label>
        <div class="layui-input-inline">
            <input type="text" name="refundFee" id="refundFee" autocomplete="off" required
                   class="layui-input">
        </div>
    </div>
    <button class="layui-btn" id="formSubmit" lay-submit="" lay-filter="formSubmit" style="display: none">立即提交</button>
</form>
<script th:replace="/common/inc::incJs"></script>
<script>
    var form = layui.form;
    var successCallback;
    var id = getQueryString("id");
    var billFee = getQueryString("billFee");
    $("#id").val(id);
    $("#billFee").val(billFee);

    //监听提交
    form.on('submit(formSubmit)', function (data) {
        if ($("#refundNo").val() == "") {
            layer.msg("退款凭证号不能为空");
        } else if ($("#refundFee").val() == "") {
            layer.msg("退款金额不能为空");
        } else if ($("#refundFee").val() >$("#billFee").val()) {
            layer.msg("退款金额不能大于订单总金额");
        } else {
            data.field.status = 1;
            $.post('/backend/security/billRefund/updateBillRefund', data.field, function (res) {
                if (res.code < 0) {
                    layer.msg(res.message);
                }
                else {
                    successCallback && successCallback();
                    layer.msg("更新成功");
                }
            });
        }
        return false;
    });

    var formSubmit = function (callback) {
        successCallback = callback;
        $("#formSubmit").click();
    };


    $(function () {

    })
</script>
</body>
</html>
